$(function () {
    initEvent();
    $(".eye-icon").click(function(){
        if(!$(this).hasClass("on")){
            $(this).addClass("on");
            $("#password").attr("type","number");
        }else{
            $(this).removeClass("on");
            $("#password").attr("type","password");
        }
    });
});

function initEvent() {
    $("#loginClick").off('click').on('click', function () {
        btn_Submit();
    });
}

function btn_Submit() {
    var username = $("#username").val();
    var password = $("#password").val();
    
    var result = common.checkForm().checkMobile(username, function (result, error) {
        if ('' == $.trim(username) || $.trim(username) == $("#username").attr('placeholder')) {
            falert('请输入手机号码');
            return false;
        } else if (result == false) {
            falert(error);
            return false;
        }
    }).checkPwd(password, function (result, error) {
        if ('' == $.trim(password) || $.trim(password) == $("#password").attr('placeholder')) {
            falert('请输入密码');
            return false;
        } else if (result == false) {
            falert(error);
            return false;
        }
    }).value;

    if (result == true) {
        var datas = {
            interface:'login@payLogin',
            username: username, 
            password: password
        };
        common.ajax({
            data: datas,
            success: function (data) {
                if (data.status == '2000') {
                    //登录成功
                    location.href = data.result.jumpUrl;
                } else if (data.status == '5000') {
                    falert(data.msg);
                }
            }
        });
    }
}
